package com.company;

//单例模式
//调用   Singleton.getInstance().setName("123123");
public class Singleton {
    //懒汉式写法不推荐
    //private static Singleton sing = null;
    //一般用饿汉式写法
    private static Singleton sing = new Singleton();
    private Singleton() {

    }

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static Singleton getInstance() {
        //懒汉写法 在多线程中可能会抢占资源，导致重复
        //if (null == sing) {
        //    sing = new Singleton();
        //}
        return sing;
    }

}
